﻿using System.IO;
using System.ServiceModel;

namespace RRSimulator.BlobManager.Service.Requests
{
    [MessageContract]
    public class UploadFileStreamRequest : BlobManagerMessageRequestBase
    {
        private bool _isDisposed;

        [MessageHeader(MustUnderstand = true)]
        public string ContentType { get; set; }

        [MessageHeader(MustUnderstand = true)]
        public string HashValue { get; set; }

        [MessageBodyMember]
        public Stream FileStream { get; set; }

        protected override void Dispose(bool isDisposing)
        {
            if (!_isDisposed)
            {
                if (isDisposing)
                {
                    if (FileStream != null)
                    {
                        FileStream.Close();
                        FileStream.Dispose();
                        FileStream = null;
                    }

                    ContentType = null;
                    HashValue = null;
                }

                _isDisposed = true;
            }

            base.Dispose(isDisposing);
        }
    }
}
